package communicationMessages;

import data.Member;
import data.MemberDataBase;

public class RegisterMessage extends Message {

	@Override
	public String getAnswer() {
		String ans;
		String userName,password;
		String arr[] = this.getContent().split("\n");
		if (arr.length == 2)
		{
			userName = arr[0];
			password = arr[1];
		}
		else
		{
			ans = "wrong format\n";
			return ans;
		}
		MemberDataBase uDataBase = MemberDataBase.getMembersDataBase();
		if (!userName.equalsIgnoreCase("guest") && uDataBase.addNewMember(userName, password))
		{
			Member u = uDataBase.getMember(userName);
			uDataBase.addLoginMember(u);
			ans ="register\nsuccess\n";
			// TODO need to add user to logins
		}
		else{
			ans = "register\nfailed\nuser name allready exist\n";
		}
		return ans;
	}

}
